<template>
    <div class="share-img">
        <img :src="imgUrl">
    </div>
</template>
<script>
import wxShare from '../../config/wxShare.js';
export default {
    name: "friend",
    data() {
        return {
            QINIUtoken: '',
            imgUrl: '',
            userSource: {},
            contSource: {}
        };
    },
    methods: {

        // 方法
        getImages() {
            let _this = this;
            let params = {
                url: location.href.split('#')[0] + '?share_id=' + localStorage.getItem('token') + '&from=123',
            };
            this.$post("/index/get_qrcode", params)
                .then(res => {
                    if (res.code === 20000) {
                        this.imgUrl = res.data.img_url
                    }
                })
                .catch(err => { });
        },
        getUserInfo() {
            let params = {
                member_id: localStorage.getItem('token'),
            };
            this.$post("/member/get_info", params)
                .then(res => {
                    if (res.code === 20000) {
                        this.userSource = res.data
                        this.getShareConfig()
                    }
                })
                .catch(err => { });
        },
        getShareConfig() {
            let params = {
                url: location.href.split('#')[0],
            };
            this.$post("/index/share", params)
                .then(res => {
                    if (res.code === 20000) {
                        wxShare(res.data, this.userSource, this.WXShareSuccess)
                    }
                })
                .catch(err => { });
        },
        WXShareSuccess() {
            this.$dialog.toast({ mes: '分享成功', timeout: 1000 });
        }
    },
    beforeCreate() {
        document.querySelector("body").setAttribute("style", "background-color:#fff");
    },
    created() {
        this.getImages()
        this.getUserInfo()

    },
};
</script>
<style lang="less" scoped>
.share-img {
    position: fixed;
    top: 0;
    width: 100%;
    height: 100%;
    img {
        width: 100%;
        height: 100%;
    }
}
</style>